﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<%   
String path = request.getContextPath();   
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";   
%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN">
<head>
	<jsp:include page="../inc/bootstrap.jsp"></jsp:include>
	<script type="text/javascript" src="<%=basePath%>static/js/list.js"></script>
</head>	
   	<body>
	<form action="<%=basePath %>permission/list.do" method="post" name="permissionForm" id="permissionForm" class="form-horizontal">
	<input type="hidden" name="permission_id" id="permission_id" value="${permission_id}"/>
	<input id="permission_list" value="1" type="hidden">
 	<!-- 添加资源 -->
	<div id="tools">
		<c:if test="${level != '4'}">
		<div class="maxToolButton clearfix">
			<%-- <ul>
				<shiro:hasPermission name="permission:add">
				<li class="tbtn"><button type="button" class="btn btn-sm btn-primary" onclick="userEvent('permission:add',function(){add('${level}','${permission_id}')});">新增</button></li>
				</shiro:hasPermission>
			</ul> --%>
			<div class="pull-right maintopmenu">
				<shiro:hasPermission name="permission:add">
					<button type="button" class="btn btn-primary" onclick="add('${level}','${permission_id}');">新增</button>
				</shiro:hasPermission>	
				<button type="button" class="btn btn-default winRefresh" onclick="winRefresh();">刷新</button>
			</div>
		</div>
		</c:if>
	</div>	
	<div class="orderBox clearfix">
		<div class="minw1000">
			<table id="table" class="table table-hover table-bordered table-condensed">
				<thead>
					<tr>
						<th class="w40">序号</th>
						<th class="wd4">资源名称</th>
						<th class="wd4">资源地址</th>
						<th class="wd4">权限代码</th>
						<th class="w80i">排序序号</th>
						<th class="wd2">类型</th>
						<th class="wd2">资源</th>
						<c:if test="${level == '3'}">
						<th class="wd4">按钮级别</th>
						</c:if>
						<th class="w90i">操作</th>
				</thead>	
				<tbody>
					<!-- 开始循环 -->	
					<c:choose>
						<c:when test="${not empty permissionList}">
							<c:forEach items="${permissionList}" var="pm" varStatus="vs">
							<tr>
								<td>${vs.index+1}</td>
								<td><i class="${pm.permission_icon }">&nbsp;</i>${pm.permission_name }</td>
								<td>${pm.permission_url}</td>
								<td>${pm.operate}</td>
								<td>${pm.permission_order }</td>
								<td>${pm.permission_type=='1'?'系统菜单':'业务按钮'}</td>
								<td>${pm.type=='1'?'电脑资源':'手机资源'}</td>
								<c:if test="${level == '3'}">
								<%-- <td>${pm.isaudit=='1'?pm.auditlevel:'无级别'}</td> --%>
								<td>${pm.isaudit=='1'?pm.auditlevel=='4'?'全部':pm.auditlevel:'无级别'}</td>
								</c:if>
								<td class="text-nowrap">
									<%-- <!-- 编辑资源 -->
									<shiro:hasPermission name="permission:edit">
										<button type="button" class="btn btn-sm btn-primary" onclick="userEvent('permission:edit',function(){edit('${pm.permission_id}','${pm.permission_state}','${level}')});">编辑</button>
									</shiro:hasPermission>
									<!-- 删除资源 -->
									<shiro:hasPermission name="permission:del">
										<button type="button" id="batchDel" class="btn btn-sm btn-danger" onclick="userEvent('permission:del',function(){delPermission('${pm.permission_id}','${pm.permission_state}')});">删除</button>
									</shiro:hasPermission> --%>
									<div class="opbuttons">
										<ul>
											<!-- 编辑资源 -->
										    <shiro:hasPermission name="permission:edit">
												<li>
													<a href="javascript:void(0);" onclick="edit('${pm.permission_id}','${pm.permission_state}','${level}')">编辑</a>
												</li>
											</shiro:hasPermission>
											<!-- 删除资源 -->
											<shiro:hasPermission name="permission:del">
												<li>
													<a href="javascript:void(0);" onclick="delPermission('${pm.permission_id}','${pm.permission_state}')">删除</a>
												</li>
											</shiro:hasPermission>
										</ul>
									</div>
								</td>
							</tr>
							</c:forEach>
							
						</c:when>
						<c:otherwise>
							<tr class="main_info">
								<td colspan="10" class="center">没有相关数据</td>
							</tr>
						</c:otherwise>
					</c:choose>
					
				</tbody>
			</table>
		</div>	
	</div>
	</form>
	<script type="text/javascript">
		function add(level,permission_id){
			top.diag = $.MaxDialog({
				"width":550,
				"height":500,
				"title":"新增资源",
				"type":"iframe",
				"isFooter":false,
				"url":"<%=basePath%>permission/toAdd.do?level="+level+"&permission_id="+permission_id,
				"hideBefore":function(obj){					
					if($(obj).find("iframe").contents().find("#permission_edit").val() == "1"){
						setTimeout(function(){
							jzts();
							parent.window.location.reload();
						},200);
					}
				}
			})
		}
		var form = $("#permissionForm");
		
		var table = "";
		//高级查询展开折叠时，界面的重置回调函数，覆盖advancedQuery.jsp中的resizeLayOut()方法；
		function resizeLayOut(){
			//初始化orderBox的高度
			initOrderBoxHeight();
			//表格自适应
			initTableHeight(table,$("#table"));
		};
		$(function (){
			//初始化orderBox的高度
			initOrderBoxHeight();
			//创建表格自适应对象
			table = new MaxTable($("#table"));
			//表格自适应
			initTableHeight(table,$("#table"));
		});
	  	
	    // 批量作废
		function delPermission(permission_id){
	       $.MaxDialog({
				"title":"提示",
				"type":"confirm",
				"content":"确定要删除数据吗?",
				"buttons":[
							{
								"text":"确定",
								"callback":function(){
									$.ajax({
										type: "POST",
										url: '<%=basePath%>permission/delete.do',
										data: {permission_id:permission_id,tm:new Date().getTime()},
										dataType:'json',
										cache: false,
										success: function(data){
											if (data.success){
												parent.location.href="<%=basePath%>permission/listAllPermission.do?permission_id=${permission_id}";
											}else{
												$.MaxDialog({
													"title":"提示",
													"type":"tips",
													"content":data.msg,
													"time":2
												});
											}
										},
										error: function(data){
											showError(data.msg);
										}
									});
								}
							},
							{
								"text":"取消",
								"type":"Mcancel",
								"callback":function(){
									//alert("我是取消按钮的回调函数，我没有return false时，关闭模态框");
									//return false时，不关闭模态框
								}
							}
						]
			});
	    };
	    
		function edit(permisson_id,status,level){
			 if (status == "2"){
				 $.MaxDialog({
						"title":"通知",
						"type":"tips",
						"content":"该数据状态为已作废，不能进行编辑操作!",
						"time":2,
						"hideBefore":function(){
						}
					});
				 return;
			 }
			 top.diag = $.MaxDialog({
					"width":550,
					"height":500,
					"title":"编辑资源",
					"type":"iframe",
					"isFooter":false,
					"url":"<%=basePath%>permission/toEdit.do?id="+permisson_id+"&level="+level,
					"hideBefore":function(obj){
						if($(obj).find("iframe").contents().find("#permission_edit").val() == "1"){
							parent.window.location.reload();
						}
					}
			})
		}
	</script>
</html>